<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-button v-if="training_student_add" class="filter-item" style="margin-left: 10px;" @click="handleCreate"
                 type="primary" icon="edit">添加
      </el-button>
    </div>
    <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border fit
              highlight-current-row style="width: 100%">
      <!--<el-table-column align="center" label="" v-if="dialogStatus == 'update'">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ scope.row.fid }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <el-table-column align="center" label="编码">
        <template slot-scope="scope">
          <span>{{ scope.row.fnumber }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.fname }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="年龄">
        <template slot-scope="scope">
          <span>{{ scope.row.age }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="性别">
        <template slot-scope="scope">
          <span>{{ formatSex(scope.row.sex) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="身份证号" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.idCard }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="手机号1" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.tel1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="手机号2" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.tel2 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="微信号" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.wechat }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="行业类别">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.workingType)}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="职位">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.jobType)}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="工作区域">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.workingArea) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="居住区域">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.homeArea) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="详细地址" width="260">
        <template slot-scope="scope">
          <span>{{ scope.row.homeAddress }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="报名时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.registerDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="拿证时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.finishesDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="科目一通过时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.sub1FinishesDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="科目二通过时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.sub2FinishesDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="科目三通过时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.sub3FinishesDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="科目四通过时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.sub4FinishesDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="收集时间" width="100">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.collectDate, 'yyyy-MM-dd')}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="渠道来源">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.channel) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="意向等级" width="210">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.intentionLevel) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="学员状态">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.bizStatus) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="跟进状态">
        <template slot-scope="scope">
          <span>{{ setDicData(scope.row.followUpStatus) }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="跟进人">
        <template slot-scope="scope">
          <span>{{ userIdToName(scope.row.followUpUser) }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column align="center" label="跟进次数">-->
        <!--<template scope="scope">-->
          <!--<span>{{ scope.row.callCount }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="收集人">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ userIdToName(scope.row.collectUser) }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="选择我们的原因">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ scope.row.choseReason }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="认为我们的价格">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ scope.row.priceEvaluate }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="前台接待满意度">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ scope.row.receptionEvaluate }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="校区">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ scope.row.school }}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column align="center" label="最后跟进时间" width="100">-->
        <!--<template slot-scope="scope">-->
          <!--<span>{{ formatDate(scope.row.lastFollowUpTime, 'yyyy-MM-dd')}}</span>-->
        <!--</template>-->
      <!--</el-table-column>-->

      <!--<el-table-column label="操作" width="200">-->
        <!--<template slot-scope="scope">-->
          <!--<el-button v-if="training_student_upd" size="mini" type="success"-->
                     <!--@click="handleUpdate(scope.row)">编辑-->
          <!--</el-button>-->
          <!--&lt;!&ndash;<el-button v-if="training_student_del" size="mini" type="danger"&ndash;&gt;-->
                     <!--&lt;!&ndash;@click="handleDelete(scope.row)">删除&ndash;&gt;-->
          <!--&lt;!&ndash;</el-button>&ndash;&gt;-->
        <!--</template>-->
      <!--</el-table-column>-->
    </el-table>
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page.sync="listQuery.page"
                     :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                     layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" @close="cancel('form')">
      <el-form :model="form" :rules="rules" ref="form" size="mini" label-width="100px">
        <el-form-item label="编码" prop="fid" v-if="dialogStatus == 'update'">
          <el-input v-model="form.fid" placeholder="" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="编码" prop="fnumber">
          <el-input v-model="form.fnumber" placeholder="编码"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="fname">
          <el-input v-model="form.fname" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="年龄"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-input v-model="form.sex" placeholder="性别"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
          <el-input v-model="form.idCard" placeholder="身份证号"></el-input>
        </el-form-item>
        <el-form-item label="手机号1" prop="tel1">
          <el-input v-model="form.tel1" placeholder="手机号1"></el-input>
        </el-form-item>
        <el-form-item label="手机号1" prop="tel2">
          <el-input v-model="form.tel2" placeholder="手机号1"></el-input>
        </el-form-item>
        <el-form-item label="微信号" prop="wechat">
          <el-input v-model="form.wechat" placeholder="微信号"></el-input>
        </el-form-item>
        <el-form-item label="行业类别" prop="workingType">
          <el-input v-model="form.workingType" placeholder="行业类别"></el-input>
        </el-form-item>
        <el-form-item label="职位" prop="jobType">
          <el-input v-model="form.jobType" placeholder="职位"></el-input>
        </el-form-item>
        <el-form-item label="工作区域" prop="workingArea">
          <el-input v-model="form.workingArea" placeholder="工作区域"></el-input>
        </el-form-item>
        <el-form-item label="居住区域" prop="homeArea">
          <el-input v-model="form.homeArea" placeholder="居住区域"></el-input>
        </el-form-item>
        <el-form-item label="详细地址" prop="homeAddress">
          <el-input v-model="form.homeAddress" placeholder="详细地址"></el-input>
        </el-form-item>
        <el-form-item label="报名时间" prop="registerDate">
          <el-input v-model="form.registerDate" placeholder="报名时间"></el-input>
        </el-form-item>
        <el-form-item label="拿证时间" prop="finishesDate">
          <el-input v-model="form.finishesDate" placeholder="拿证时间"></el-input>
        </el-form-item>
        <el-form-item label="科目一通过时间" prop="sub1FinishesDate">
          <el-input v-model="form.sub1FinishesDate" placeholder="科目一通过时间"></el-input>
        </el-form-item>
        <el-form-item label="科目二通过时间" prop="sub2FinishesDate">
          <el-input v-model="form.sub2FinishesDate" placeholder="科目二通过时间"></el-input>
        </el-form-item>
        <el-form-item label="科目三通过时间" prop="sub3FinishesDate">
          <el-input v-model="form.sub3FinishesDate" placeholder="科目三通过时间"></el-input>
        </el-form-item>
        <el-form-item label="科目四通过时间" prop="sub4FinishesDate">
          <el-input v-model="form.sub4FinishesDate" placeholder="科目四通过时间"></el-input>
        </el-form-item>
        <el-form-item label="收集时间" prop="collectDate">
          <el-input v-model="form.collectDate" placeholder="收集时间"></el-input>
        </el-form-item>
        <el-form-item label="渠道来源" prop="channel">
          <el-input v-model="form.channel" placeholder="渠道来源"></el-input>
        </el-form-item>
        <el-form-item label="意向等级" prop="intentionLevel">
          <el-input v-model="form.intentionLevel" placeholder="意向等级"></el-input>
        </el-form-item>
        <el-form-item label="学员状态" prop="bizStatus">
          <el-input v-model="form.bizStatus" placeholder="学员状态"></el-input>
        </el-form-item>
        <el-form-item label="跟进状态" prop="followUpStatus">
          <el-input v-model="form.followUpStatus" placeholder="跟进状态"></el-input>
        </el-form-item>
        <el-form-item label="跟进人" prop="followUpUser">
          <el-input v-model="form.followUpUser" placeholder="跟进人"></el-input>
        </el-form-item>
        <el-form-item label="跟进次数" prop="callCount">
          <el-input v-model="form.callCount" placeholder="跟进次数"></el-input>
        </el-form-item>
        <el-form-item label="收集人" prop="collectUser">
          <el-input v-model="form.collectUser" placeholder="收集人"></el-input>
        </el-form-item>
        <el-form-item label="选择我们的原因" prop="choseReason">
          <el-input v-model="form.choseReason" placeholder="选择我们的原因"></el-input>
        </el-form-item>
        <el-form-item label="认为我们的价格" prop="priceEvaluate">
          <el-input v-model="form.priceEvaluate" placeholder="认为我们的价格"></el-input>
        </el-form-item>
        <el-form-item label="前台接待满意度" prop="receptionEvaluate">
          <el-input v-model="form.receptionEvaluate" placeholder="前台接待满意度"></el-input>
        </el-form-item>
        <el-form-item label="校区" prop="school">
          <el-input v-model="form.school" placeholder="校区"></el-input>
        </el-form-item>
        <el-form-item label="最后跟进时间" prop="lastFollowUpTime">
          <el-input v-model="form.lastFollowUpTime" placeholder="最后跟进时间"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel('form')">取 消</el-button>
        <el-button v-if="dialogStatus=='create'" type="primary" @click="create('form')">确 定</el-button>
        <el-button v-else type="primary" @click="update('form')">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {fetchList, addObj, putObj, delObj} from '@/api/training/training_student'
  import waves from '@/directive/waves/index.js' // 水波纹指令
  import { initDicList, loadByType } from '@/api/dict'
  import { getIdName, getIdNameList ,getDeptUserTree} from '@/api/user'
  import {mapGetters} from 'vuex'
  import {formatDateS, findParent2 } from '@/util/util.js'
  import {} from '@/api/dict'
  export default {
    name: 'table_training_student',
    directives: {
      waves
    },
    data() {
      return {
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          total: 0, //  总共有多少页
          page: 1,
          limit: 20
        },
        totalPage: null,
        callListQuery: {
          page: 1,
          limit: 20
        },
        rules: {
          fid: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          fnumber: [
            {required: true, message: '请输入编码', trigger: 'blur'}
          ],
          fname: [
            {required: true, message: '请输入姓名', trigger: 'blur'}
          ],
          age: [
            {required: true, message: '请输入年龄', trigger: 'blur'}
          ],
          sex: [
            {required: true, message: '请输入性别', trigger: 'blur'}
          ],
          idCard: [
            {required: true, message: '请输入身份证号', trigger: 'blur'}
          ],
          tel1: [
            {required: true, message: '请输入手机号1', trigger: 'blur'}
          ],
          tel2: [
            {required: true, message: '请输入手机号1', trigger: 'blur'}
          ],
          wechat: [
            {required: true, message: '请输入微信号', trigger: 'blur'}
          ],
          workingType: [
            {required: true, message: '请输入行业类别', trigger: 'blur'}
          ],
          jobType: [
            {required: true, message: '请输入职位', trigger: 'blur'}
          ],
          workingArea: [
            {required: true, message: '请输入工作区域', trigger: 'blur'}
          ],
          homeArea: [
            {required: true, message: '请输入居住区域', trigger: 'blur'}
          ],
          homeAddress: [
            {required: true, message: '请输入详细地址', trigger: 'blur'}
          ],
          registerDate: [
            {required: true, message: '请输入报名时间', trigger: 'blur'}
          ],
          finishesDate: [
            {required: true, message: '请输入拿证时间', trigger: 'blur'}
          ],
          sub1FinishesDate: [
            {required: true, message: '请输入科目一通过时间', trigger: 'blur'}
          ],
          sub2FinishesDate: [
            {required: true, message: '请输入科目二通过时间', trigger: 'blur'}
          ],
          sub3FinishesDate: [
            {required: true, message: '请输入科目三通过时间', trigger: 'blur'}
          ],
          sub4FinishesDate: [
            {required: true, message: '请输入科目四通过时间', trigger: 'blur'}
          ],
          collectDate: [
            {required: true, message: '请输入收集时间', trigger: 'blur'}
          ],
          channel: [
            {required: true, message: '请输入渠道来源', trigger: 'blur'}
          ],
          intentionLevel: [
            {required: true, message: '请输入意向等级', trigger: 'blur'}
          ],
          bizStatus: [
            {required: true, message: '请输入学员状态', trigger: 'blur'}
          ],
          followUpStatus: [
            {required: true, message: '请输入跟进状态', trigger: 'blur'}
          ],
          followUpUser: [
            {required: true, message: '请输入跟进人', trigger: 'blur'}
          ],
          callCount: [
            {required: true, message: '请输入跟进次数', trigger: 'blur'}
          ],
          collectUser: [
            {required: true, message: '请输入收集人', trigger: 'blur'}
          ],
          createUser: [
            {required: true, message: '请输入创建人', trigger: 'blur'}
          ],
          createTime: [
            {required: true, message: '请输入创建时间', trigger: 'blur'}
          ],
          updateTime: [
            {required: true, message: '请输入最后修改时间', trigger: 'blur'}
          ],
          updateUser: [
            {required: true, message: '请输入最后修改人', trigger: 'blur'}
          ],
          choseReason: [
            {required: true, message: '请输入选择我们的原因', trigger: 'blur'}
          ],
          priceEvaluate: [
            {required: true, message: '请输入认为我们的价格', trigger: 'blur'}
          ],
          receptionEvaluate: [
            {required: true, message: '请输入前台接待满意度', trigger: 'blur'}
          ],
          school: [
            {required: true, message: '请输入校区', trigger: 'blur'}
          ],
          version: [
            {required: true, message: '请输入版本', trigger: 'blur'}
          ],
          delFlag: [
            {required: true, message: '请输入删除标识', trigger: 'blur'}
          ],
          lastFollowUpTime: [
            {required: true, message: '请输入最后跟进时间', trigger: 'blur'}
          ]
        },
        form: {
          fid: '',
          fnumber: '',
          fname: '',
          age: '',
          sex: '',
          idCard: '',
          tel1: '',
          tel2: '',
          wechat: '',
          workingType: '',
          jobType: '',
          workingArea: '',
          homeArea: '',
          homeAddress: '',
          registerDate: '',
          finishesDate: '',
          sub1FinishesDate: '',
          sub2FinishesDate: '',
          sub3FinishesDate: '',
          sub4FinishesDate: '',
          collectDate: '',
          channel: '',
          intentionLevel: '',
          bizStatus: '',
          followUpStatus: '',
          followUpUser: '',
          callCount: '',
          collectUser: '',
          createUser: '',
          createTime: '',
          updateTime: '',
          updateUser: '',
          choseReason: '',
          priceEvaluate: '',
          receptionEvaluate: '',
          school: '',
          version: '',
          delFlag: '',
          lastFollowUpTime: ''
        },
        infoDictData: {}, // 数据字典
        dialogFormVisible: false,
        dialogStatus: '',
        training_student_add: false,
        training_student_upd: false,
        training_student_del: false,
        textMap: {
          update: '编辑',
          create: '创建'
        },
        tableKey: 0,
        dictMap: [],
        user: [],
        sex: [
          {1: '男'},
          {0: '女'}
        ]
      }
    },
    computed: {
      ...mapGetters([
        'permissions'
      ])
    },
    filters: {
      statusFilter(status) {
        const statusMap = {
          1: '有效',
          0: '无效'
        }
        return statusMap[status]
      }
    },
    created() {
      this.initUserDic()
      this.getList()
      this.getDicList()
      this.infoDict()
      this.training_student_add = this.permissions['training_student_add']
      this.training_student_upd = this.permissions['training_student_upd']
      this.training_student_del = this.permissions['training_student_del']
    },
    methods: {
      infoDict() {
        loadByType('register_mode').then(response => {
          this.infoForm.registerMode = response.data
        })
        loadByType('class_type').then(response => {
          this.infoForm.classType = response.data
        })
        loadByType('pa_type').then(response => {
          this.infoForm.payType = response.data
        })
        loadByType('school_area').then(response => {
          this.infoForm.schoolArea = response.data
          this.infoTabel.school = response.data
        })
        getIdName().then(response => {
          this.infoForm.createUser.push(response.data)
        })
        loadByType('training_subject').then(response => {
          this.infoForm.trainingSubject = response.data
        })
        getIdNameList().then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.infoForm.coachId[i] = {'label': response.data[i].username, 'value': response.data[i].userId}
            this.infoTabel.user[i] = {'label': response.data[i].username, 'value': response.data[i].userId}
          }
        })
      },
      initUserDic() {
        getDeptUserTree().then(response => {
          this.users = response.data
          console.log(this.users)
        })
      },
      userIdToName(userId) {
        console.log(this.users)
        console.log(userId)
        return findParent2(this.users, userId)
      },
      setDicData(value) {
        for (let i = 0; i < this.dictMap.length; i++) {
          for (var key in this.dictMap[i]) {
            if (key === value) {
              return this.dictMap[i][key]
            }
          }
        }
      },
      getDicList() {
        initDicList().then(response => {
          this.dictMap = response.data
        })
      },
      formatSex(sex) {
        for (var i = 0; i < this.sex.length; i++) {
          for (var key in this.sex[i]) {
            if (key == sex) {
              return this.sex[i][key]
            }
          }
        }
      },
      formatDate(date, format) {
        if (date != null) {
          return formatDateS(new Date(date), format)
        } else {
          return '-'
        }
      },
      getList() {
        this.listLoading = true
        fetchList({page: this.listQuery.page, limit: this.listQuery.limit}).then(response => {
          this.list = response.data.records
          this.total = response.data.total
          this.listLoading = false
        })
      },
      handleSizeChange(val) {
        this.listQuery.limit = val
        this.getList()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.getList()
      },
      handleDelete(row) {
        delObj(row)
          .then(response => {
            this.dialogFormVisible = false
            this.getList()
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
          })
      },
      handleUpdate(row) {
        this.dialogStatus = 'update'
        this.dialogFormVisible = true
        this.form.fid = row.fid
        this.form.fnumber = row.fnumber
        this.form.fname = row.fname
        this.form.age = row.age
        this.form.sex = row.sex
        this.form.idCard = row.idCard
        this.form.tel1 = row.tel1
        this.form.tel2 = row.tel2
        this.form.wechat = row.wechat
        this.form.workingType = row.workingType
        this.form.jobType = row.jobType
        this.form.workingArea = row.workingArea
        this.form.homeArea = row.homeArea
        this.form.homeAddress = row.homeAddress
        this.form.registerDate = row.registerDate
        this.form.finishesDate = row.finishesDate
        this.form.sub1FinishesDate = row.sub1FinishesDate
        this.form.sub2FinishesDate = row.sub2FinishesDate
        this.form.sub3FinishesDate = row.sub3FinishesDate
        this.form.sub4FinishesDate = row.sub4FinishesDate
        this.form.collectDate = row.collectDate
        this.form.channel = row.channel
        this.form.intentionLevel = row.intentionLevel
        this.form.bizStatus = row.bizStatus
        this.form.followUpStatus = row.followUpStatus
        this.form.followUpUser = row.followUpUser
        this.form.callCount = row.callCount
        this.form.collectUser = row.collectUser
        this.form.createUser = row.createUser
        this.form.createTime = row.createTime
        this.form.updateTime = row.updateTime
        this.form.updateUser = row.updateUser
        this.form.choseReason = row.choseReason
        this.form.priceEvaluate = row.priceEvaluate
        this.form.receptionEvaluate = row.receptionEvaluate
        this.form.school = row.school
        this.form.version = row.version
        this.form.delFlag = row.delFlag
        this.form.lastFollowUpTime = row.lastFollowUpTime
      },
      handleCreate() {
        this.dialogStatus = 'create'
        this.dialogFormVisible = true
      },
      create(formName) {
        const set = this.$refs
        set[formName].validate(valid => {
          if (valid) {
            addObj(this.form)
              .then(() => {
                this.dialogFormVisible = false
                this.getList()
                this.$notify({
                  title: '成功',
                  message: '创建成功',
                  type: 'success',
                  duration: 2000
                })
                const set = this.$refs
                set[formName].resetFields()
              })
          } else {
            return false
          }
        })
      },
      cancel(formName) {
        this.dialogFormVisible = false
        const set = this.$refs
        set[formName].resetFields()
      },
      update(formName) {
        const set = this.$refs
        set[formName].validate(valid => {
          if (valid) {
            this.dialogFormVisible = false
            this.form.password = undefined
            putObj(this.form).then(() => {
              this.dialogFormVisible = false
              this.getList()
              const set = this.$refs
              set[formName].resetFields()
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success',
                duration: 2000
              })
            })
          } else {
            return false
          }
        })
      }
    }
  }
</script>
